﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Yuyi.PluginForJS.JavaScriptLexer
{
    public static class Tokens
    {
        // ----- terminal classes -----
        public const int EOF = 0;
        public const int Identifier = 1;
        public const int Literal = 2;

        // ----- special character -----
        /// <summary>
        /// "="
        /// </summary>
        public const int Assign = 3;
        /// <summary>
        /// "+"
        /// </summary>
        public const int Plus = 4;
        /// <summary>
        /// "-"
        /// </summary>
        public const int Minus = 5;
        public const int Times = 6;
        /// <summary>
        ///  "/"
        /// </summary>
        public const int Div = 7;
        /// <summary>
        /// "%"
        /// </summary>
        public const int Mod = 8;
        /// <summary>
        /// ":"
        /// </summary>
        public const int Colon = 9;
        /// <summary>
        /// "::"
        /// </summary>
        public const int DoubleColon = 10;
        /// <summary>
        /// ";"
        /// </summary>
        public const int Semicolon = 11;
        /// <summary>
        /// "?"
        /// </summary>
        public const int Question = 12;
        /// <summary>
        /// ","
        /// </summary>
        public const int Comma = 14;
        /// <summary>
        /// "."
        /// </summary>
        public const int Dot = 15;
        /// <summary>
        /// "{"
        /// </summary>
        public const int OpenCurlyBrace = 16;
        /// <summary>
        /// "}"
        /// </summary>
        public const int CloseCurlyBrace = 17;
      
        public const int OpenSquareBracket = 18;
        public const int CloseSquareBracket = 19;
        /// <summary>
        /// "("
        /// </summary>
        public const int OpenParenthesis = 20;
        /// <summary>
        /// ")"
        /// </summary>
        public const int CloseParenthesis = 21;
        public const int GreaterThan = 22;
        public const int LessThan = 23;
        public const int Not = 24;
        public const int LogicalAnd = 25;
        public const int LogicalOr = 26;
        public const int BitwiseComplement = 27;
        public const int BitwiseAnd = 28;
        public const int BitwiseOr = 29;
        public const int Xor = 30;
        public const int Increment = 31;
        public const int Decrement = 32;
        public const int Equal = 33;
        public const int NotEqual = 34;
        public const int GreaterEqual = 35;
        public const int LessEqual = 36;
        public const int ShiftLeft = 37;
        public const int PlusAssign = 38;
        public const int MinusAssign = 39;
        public const int TimesAssign = 40;
        public const int DivAssign = 41;
        public const int ModAssign = 42;
        public const int BitwiseAndAssign = 43;
        public const int BitwiseOrAssign = 44;
        public const int XorAssign = 45;
        public const int ShiftLeftAssign = 46;
        public const int Pointer = 47;
        public const int LambdaArrow = 48;

        // ----- keywords -----
        public const int Break = 49;
        public const int False = 50;
        public const int In = 51;
        public const int This = 52;
        public const int Void = 53;
        public const int Continue = 54;
        public const int For = 55;
        public const int New = 56;
        public const int True = 57;
        public const int While = 58;
        public const int Delete = 59;
        public const int Function = 60;
        public const int Null = 61;
        public const int Typeof = 62;
        public const int With = 63;
        public const int Else = 64;
        public const int If = 65;
        public const int Return = 66;
        public const int Var = 67;
        public const int Case = 68;
        public const int Debugger = 69;
        public const int Export = 70;
        public const int Super = 71;
        public const int Catch = 72;
        public const int Default = 73;
        public const int Extends = 74;
        public const int Switch = 75;
        public const int Class = 76;
        public const int Do = 77;
        public const int Finally = 78;
        public const int Throw = 79;
        public const int Const = 80;
        public const int Enum = 81;
        public const int Import = 82;
        public const int Try = 83;

        public const int EndOfLine = 84;

        new public const int Equals = 85;


        public const int MaxToken = 86;
        static BitArray NewSet(params int[] values)
        {
            BitArray bitArray = new BitArray(MaxToken);
            foreach (int val in values)
            {
                bitArray[val] = true;
            }
            
            return bitArray;
        }
        public static BitArray UnaryExpressionSet = NewSet(Delete,Void,Typeof,Increment,Decrement,Plus,Minus,BitwiseComplement,Not);
        public static BitArray PostfixExpressionSet = NewSet(Increment,Decrement);
        public static BitArray AssignmentOperatorSet = NewSet(Assign,PlusAssign,MinusAssign,TimesAssign,DivAssign,ModAssign,BitwiseAndAssign,
            BitwiseOrAssign,XorAssign,NotEqual,Equal,LessEqual,GreaterEqual);
        public static BitArray PostfixMemberExpressionSet = NewSet(Dot,OpenSquareBracket,OpenParenthesis);
        static string[] tokenList = new string[] {
			// ----- terminal classes -----
			"<EOF>",
			"<Identifier>",
			"<Literal>",
			// ----- special character -----
			"=",
			"+",
			"-",
			"*",
			"/",
			"%",
			":",
			"::",
			";",
			"?",
			"??",
			",",
			".",
			"{",
			"}",
			"[",
			"]",
			"(",
			")",
			">",
			"<",
			"!",
			"&&",
			"||",
			"~",
			"&",
			"|",
			"^",
			"++",
			"--",
			"==",
			"!=",
			">=",
			"<=",
			"<<",
			"+=",
			"-=",
			"*=",
			"/=",
			"%=",
			"&=",
			"|=",
			"^=",
			"<<=",
			"->",
			"=>",
			// ----- keywords -----
			"break",
            "false",
            "in",
            "this",
            "void",
            "continue",
            "for",
            "new",
            "true",
            "while",
            "delete",
            "function",
            "null",
            "typeof",
            "with",
            "else",
            "if",
            "return",
            "var",
            "case",
            "debugger",
            "export",
            "super",
            "catch",
            "default",
            "extends",
            "switch",
            "class",
            "do",
            "finally",
            "throw",
            "const",
            "enum",
            "import",
            "try",
            "\r\n"
		};
        public static string GetTokenString(int token)
        {
            if (token >= 0 && token < tokenList.Length)
            {
                return tokenList[token];
            }
            throw new System.NotSupportedException("Unknown token:" + token);
        }
    }
}
